<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace Plugin\Organization\Http\Controller\Api;

use App\Http\Admin\Controller\AbstractController as AdminAbstractController;
use App\Http\Common\Middleware\AccessTokenMiddleware;
use App\Http\Common\Result;
use App\Http\CurrentUser;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Request;
use Hyperf\Swagger\Annotation\Get;
use Hyperf\Swagger\Annotation\HyperfServer;
use Hyperf\Swagger\Annotation\Post;
use Plugin\Organization\Service\RdOrganizeUserStandService;

/**
 * 用户管理站点控制器
 * Class RdOrganizeUserStandApiController
 */
#[HyperfServer(name: 'http')]
#[Middleware(middleware: AccessTokenMiddleware::class, priority: 100)]
final class RdOrganizeUserStandApiController extends AdminAbstractController
{

     /**
     * 业务处理服务
     * RdOrganizeUserStandService
     */
    public function __construct(
        protected readonly RdOrganizeUserStandService $service,
        protected readonly CurrentUser $currentUser
    ) {}

    #[Get(
        path: '/organization/rdOrganizeUserStand/tree',
        summary: '用户管理站点控制器详情',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['用户管理站点控制器']
    )]
    public function tree(Request $request): Result
    {
        return $this->success(data: $this->service->getUserStandTree($request->all()['user_id'] ?? $this->currentUser->id()));
    }

    #[Post(
        path: '/organization/rdOrganizeUserStand/default',
        summary: '设置默认站点',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['用户管理站点控制器']
    )]
    public function default(Request $request): Result
    {
        return $this->success(data: $this->service->setDefault($this->currentUser->id(), $request->all()['stand_id']));
    }

    #[Get(
        path: '/organization/rdOrganizeUserStand/default',
        summary: '获取默认站点',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['用户管理站点控制器']
    )]
    public function getDefault(): Result
    {
        return $this->success(data: $this->service->getDefault($this->currentUser->id()));
    }

    #[Get(
        path: '/organization/rdOrganizeUserStand/standUser/{stand_id}',
        summary: '用户管理站点控制器列表',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['用户管理站点控制器']
    )]
    public function standUser(int $stand_id): Result
    {
        return $this->success(data: $this->service->getStandUser($stand_id));
    }

}